package com.zwy.leetcode;

class MinStack {

    private int[] data=new int[100];
    private int top;
    /** initialize your data structure here. */
    public MinStack() {
        this.top=-1;

    }
    public void push(int val) {
        if(top<100){
            top++;
            data[top]=val;
        }
    }

    public void pop() {
       if(top>=0)
        this.top--;
    }

    public int top() {
        if(top>=0)return data[top];
        else return  -1;
    }

    public int getMin() {
        int min = data[0];
        if(top>=0) {
            for (int i = 0; i < top + 1; i++) {
                min = Math.min(min, data[i]);
            }
            return min;
        }
        return min;
    }
}